#ifndef _COMM_H_
#define _COMM_H_

#include <stddef.h>
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>

#include "ringbuffer.h"


#define MAX(a,b) ( ((a)>(b)) ? (a):(b) )
#define MIN(a,b) ( ((a)>(b)) ? (b):(a) )


#define MAXCOMMTYPENAME		16
#define MAXBUFLEN 1024


class comm
{
public:
	comm(void);
	virtual ~comm(void);

	virtual int open(void * comm_para) = 0;
	virtual int write(char * p_data, size_t length) = 0;
	virtual int read(char * p_data, size_t req_len) = 0;
	virtual int read_a_line(char * p_data, size_t req_len) = 0;
	virtual int close() = 0;
	virtual int flush() = 0;
	sem_t *get_semaphore();
	#if 0
	void set_status(int comm_status);
	int get_status();	
	void set_comm_type(char *type_name);
	void get_comm_type(char *ret_type_name,size_t max_len);		
	void clear_comm_type();
	#endif
protected:
	buffer *mBuf;
	sem_t mSemCanRead;

private:
	//virtual void read_thread(void *thread_para) = 0;
	
	
	//pthread_t mReadThread;
	#if 0
	char comm_type[MAXCOMMTYPENAME];	//通信类型
	int status;
	#endif
};



#endif